SDK_DIR := $(shell cd $(shell pwd)/../.. && /bin/pwd)
include $(SDK_DIR)/build/base.mk

###############################################################################
#
#  Copyright (c) Hunan Goke,Chengdu Goke,Shandong Goke. 2021.
#  All rights reserved.
#  Create By Caizhiyong 2021/3/16
#
###############################################################################

CROSS_COMPILE   := $(CONFIG_GK_ARM_TOOLCHAINS_NAME)
STRIP := $(CROSS_COMPILE)-strip
ROOTFS_PREFIX   := $(GK_ROOTFS_DIR)
ROOTFS_BUILDDIR ?= $(shell pwd)/.build
ROOTFS_SRCDIR   := $(if $(ROOTFS_DIR),$(ROOTFS_DIR),$(shell pwd))

MKFLAGS := PREFIX=$(ROOTFS_PREFIX) \
	CROSS_COMPILE=$(CROSS_COMPILE)- \
	CONFIG_LIBCPP_SUPPORT=$(CONFIG_GK_LIBCPP_SUPPORT) \
	CONFIG_ETH_SUPPORT=y

.PHONY: all clean

all: rootfs_strip_$(CONFIG_GK_ROOTFS_STRIP)
	@echo;
	@echo 'File system is ready at "$(ROOTFS_PREFIX)"'
	@echo;

clean:
	rm -rf $(ROOTFS_BUILDDIR)
	rm -rf $(ROOTFS_PREFIX)

.PHONY: rootfs_strip_y
rootfs_strip_y: rootfs_unstrip
	@set -e; for ix in $$(find $(ROOTFS_PREFIX)/ -type f ); \
	    do ( \
	        FILEINFO=$$(file -b $${ix}); \
	        if [ "s$$(echo $${FILEINFO} | \
	              grep '^ELF ..-bit LSB ')" != "s" ]; \
	            then ( \
	                 $(STRIP) $${ix}; \
	        ) fi; \
	    ) done

.PHONY: rootfs_strip_ rootfs_strip_n rootfs_unstrip
rootfs_strip_ rootfs_strip_n: rootfs_unstrip

TOOLS.y = scripts eudev busybox
TOOLS.$(CONFIG_GK_E2FSPROGS_SUPPORT)  += e2fsprogs
TOOLS.$(CONFIG_GK_GDB_SUPPORT)        += gdb
TOOLS.$(CONFIG_GK_REG_SUPPORT)        += regtools
TOOLS.$(CONFIG_GK_MIITOOLS_SUPPORT)   += ethtools
TOOLS.$(CONFIG_GK_DOSFS_SUPPORT)      += mkdosfs
TOOLS.$(CONFIG_GK_MTDUTILS_SUPPORT)   += mtd-utils

include $(foreach utils,$(TOOLS.y),$(ROOTFS_SRCDIR)/$(utils)/Makefile)
